<?php

namespace My\Controller;

use Utuo\BackgroundController;

class MillionaireController extends BackgroundController {
	// init
	public function _initialize() {
		$this->setControllerTitle('全民大富翁');
		$this->setActionTitle(array (
				'index' => '游戏管理',
				'add' => '添加游戏',
				'recycle' => '回收站',
				'modify' => '修改游戏',
				'delete' => '删除游戏' 
		));
		
		$this->setActionNav('index,add,recycle');
	}
	
	// getList
	public function getLists($is_deleted) {
		$page = $this->getPage();
		$pagesize = $this->getPageSize();
		$d = D('Millionaire');
		$condition = array (
				'cid' => $this->aid,
				'is_deleted' => $is_deleted,
		);
		$list = $d->where($condition)->limit($pagesize)->page($page)->order('id DESC')->select();
		$count = $d->where($condition)->count();
		foreach ($list as &$v){
			$v['activityUrl'] = $this->getUrl($this->aid, $v['id']);
		}
		$this->assign('itemList', $list);
		$this->showPage($count, $pagesize);
		$this->display();
	}
	
	// modify
	public function modify(){
		$item = D('Millionaire')->getOneById();
		$this->assign('item',$item);
		$this->display('save');
	}
	
	// 获取前台活动URL
	protected function getUrl($cid,$aid) {
		$url = U('Home/Millionaire/show',array('cid'=>$cid,'aid'=>$aid),true,true);
		return $url;
	}
}